package com.laoye.mapper;

import com.laoye.bean.Order;
import com.laoye.bean.Product_Order;
import com.laoye.dto.OrderCreateDTO;
import com.laoye.dto.OrderDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {
    void addOrder(@Param("order")OrderCreateDTO  orderDto);
    void addOrderProducts(@Param("order")OrderCreateDTO order);
    Order getOrderById(@Param("id") Integer order_id);
    List<Product_Order> getProductById(@Param("id") Integer order_id);

    @Update("update `order` set pay_time=now(),status=1 where id=#{id}")
    void updateSetPayTime(@Param("id")Integer order_id);

    List<OrderDetail> getOrderList(@Param("status") Byte status);

    @Update("update `order` set status=2,delivery_time=now() where id= #{id}")
    void updateDeliveryTime(@Param("id")Integer id);

    @Update("update `order` set is_deleted=1 where id=#{id}")
    void deleteOrder(@Param("id")Integer id);

    @Update("update `order_product` set is_deleted=1 where order_id=#{order_id}")
    void deleteOrderProducts(@Param("order_id")Integer order_id);

    List<OrderDetail> getUserOrderList(@Param("status") Byte status,@Param("user_id") Integer user_id);

    @Update("update `order` set status=3 where id= #{id}")
    void completeOrder(@Param("id")Integer id);

    //获取用户id,从而获取到用户email，发送邮件，在管理员发货时发送邮件给用户
    @Select("select user_id from `order` where id= #{id}")
    Integer getUserId(@Param("id")Integer id);


    //获取Echarts数据，订单数量
    //未付款订单数量
    @Select("select count(*) from `order` where status=0")
    Integer getOrderCount1();
    //待发货订单数量
    @Select("select count(*) from `order` where status=1")
    Integer getOrderCount2();
    //待收货订单数量
    @Select("select count(*) from `order` where status=2")
    Integer getOrderCount3();
    //已完成订单数量
    @Select("select count(*) from `order` where status=3")
    Integer getOrderCount4();
}
